<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智能医疗监测系统</title>
    <link rel="stylesheet" href="style.css">
    <script src="https://cdn.jsdelivr.net/npm/chart.js@3.7.0/dist/chart.min.js"></script>
    <!-- SF Pro Display 字体 -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <!-- SF Symbols 图标 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body>
    <!-- 加载动画 -->
    <div id="loadingScreen" class="loading-screen">
        <div class="loading-content">
            <div class="loading-icon">
                <i class="fas fa-heartbeat"></i>
            </div>
            <div class="loading-text">智能医疗监测系统</div>
            <div class="loading-progress">
                <div class="progress-bar"></div>
            </div>
        </div>
    </div>

    <!-- 主应用容器 -->
    <div class="app-container">
        <!-- 侧边导航栏 -->
        <nav class="sidebar">
            <div class="sidebar-header">
                <div class="logo">
                    <i class="fas fa-heartbeat"></i>
                    <span class="logo-text">医疗监测</span>
                </div>
            </div>

            <div class="nav-menu">
                <div class="nav-item active" data-view="dashboard">
                    <i class="fas fa-chart-line"></i>
                    <span>实时监测</span>
                    <div class="nav-indicator"></div>
                </div>
                <div class="nav-item" data-view="ai">
                    <i class="fas fa-robot"></i>
                    <span>AI助手</span>
                    <div class="nav-indicator"></div>
                </div>
                <div class="nav-item" data-view="data">
                    <i class="fas fa-database"></i>
                    <span>数据管理</span>
                    <div class="nav-indicator"></div>
                </div>
                <div class="nav-item" data-view="settings">
                    <i class="fas fa-cog"></i>
                    <span>系统设置</span>
                    <div class="nav-indicator"></div>
                </div>
            </div>

            <div class="connection-status">
                <div class="status-indicator" id="connectionStatus">
                    <div class="status-dot"></div>
                    <span class="status-text">未连接</span>
                </div>
            </div>
        </nav>

        <!-- 主内容区域 -->
        <main class="main-content">
            <!-- 顶部标题栏 -->
            <header class="top-header">
                <div class="header-left">
                    <h1 class="page-title" id="pageTitle">实时监测</h1>
                    <div class="breadcrumb">
                        <span class="breadcrumb-item">医疗监测系统</span>
                        <i class="fas fa-chevron-right"></i>
                        <span class="breadcrumb-item current" id="currentBreadcrumb">实时监测</span>
                    </div>
                </div>
                <div class="header-right">
                    <div class="header-actions">
                        <button class="action-btn" id="notificationBtn">
                            <i class="fas fa-bell"></i>
                            <span class="notification-badge">3</span>
                        </button>
                        <button class="action-btn" id="settingsBtn">
                            <i class="fas fa-cog"></i>
                        </button>
                    </div>
                </div>
            </header>

            <!-- 内容区域 -->
            <div class="content-area">
                <!-- 实时监测视图 -->
                <div id="dashboardView" class="view-section active">
                    <!-- 连接状态卡片 -->
                    <div class="status-card">
                        <div class="card-header">
                            <div class="card-title">
                                <i class="fas fa-wifi"></i>
                                <span>设备连接</span>
                            </div>
                            <div class="card-actions">
                                <button id="connectBtn" class="btn-primary">
                                    <i class="fas fa-plug"></i>
                                    <span>连接</span>
                                </button>
                                <button id="disconnectBtn" class="btn-secondary" disabled>
                                    <i class="fas fa-unlink"></i>
                                    <span>断开</span>
                                </button>
                            </div>
                        </div>
                        <div class="card-content">
                            <div class="connection-form">
                                <div class="input-field">
                                    <label for="serverUrl">服务器地址</label>
                                    <input type="text" id="serverUrl" value="ws://localhost:8080" placeholder="ws://localhost:8080">
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- 实时数据卡片网格 -->
                    <div class="metrics-grid">
                        <!-- 心率监测卡片 -->
                        <div class="metric-card heart-rate">
                            <div class="metric-header">
                                <div class="metric-icon">
                                    <i class="fas fa-heartbeat"></i>
                                </div>
                                <div class="metric-info">
                                    <h3>心率监测</h3>
                                    <p>实时心率数据</p>
                                </div>
                                <div class="metric-status">
                                    <span class="status-badge normal">正常</span>
                                </div>
                            </div>
                            <div class="metric-value">
                                <span class="value" id="currentHeartRate">--</span>
                                <span class="unit">BPM</span>
                            </div>
                            <div class="metric-chart">
                                <canvas id="heartRateChart"></canvas>
                            </div>
                            <div class="metric-trend">
                                <i class="fas fa-arrow-up trend-up"></i>
                                <span>较上次 +2 BPM</span>
                            </div>
                        </div>

                        <!-- 体温监测卡片 -->
                        <div class="metric-card temperature">
                            <div class="metric-header">
                                <div class="metric-icon">
                                    <i class="fas fa-thermometer-half"></i>
                                </div>
                                <div class="metric-info">
                                    <h3>体温监测</h3>
                                    <p>实时体温数据</p>
                                </div>
                                <div class="metric-status">
                                    <span class="status-badge normal">正常</span>
                                </div>
                            </div>
                            <div class="metric-value">
                                <span class="value" id="currentTemperature">--</span>
                                <span class="unit">°C</span>
                            </div>
                            <div class="metric-chart">
                                <canvas id="temperatureChart"></canvas>
                            </div>
                            <div class="metric-trend">
                                <i class="fas fa-minus trend-stable"></i>
                                <span>稳定</span>
                            </div>
                        </div>

                        <!-- 滴速监测卡片 -->
                        <div class="metric-card drop-rate">
                            <div class="metric-header">
                                <div class="metric-icon">
                                    <i class="fas fa-tint"></i>
                                </div>
                                <div class="metric-info">
                                    <h3>滴速监测</h3>
                                    <p>实时滴速数据</p>
                                </div>
                                <div class="metric-status">
                                    <span class="status-badge normal">正常</span>
                                </div>
                            </div>
                            <div class="metric-value">
                                <span class="value" id="currentDropRate">--</span>
                                <span class="unit">滴/分钟</span>
                            </div>
                            <div class="metric-chart">
                                <canvas id="dropRateChart"></canvas>
                            </div>
                            <div class="metric-trend">
                                <i class="fas fa-arrow-down trend-down"></i>
                                <span>较上次 -3 滴/分钟</span>
                            </div>
                        </div>

                        <!-- 血氧监测卡片 -->
                        <div class="metric-card spo2">
                            <div class="metric-header">
                                <div class="metric-icon">
                                    <i class="fas fa-lungs"></i>
                                </div>
                                <div class="metric-info">
                                    <h3>血氧监测</h3>
                                    <p>实时血氧数据</p>
                                </div>
                                <div class="metric-status">
                                    <span class="status-badge normal">正常</span>
                                </div>
                            </div>
                            <div class="metric-value">
                                <span class="value" id="currentSpo2">--</span>
                                <span class="unit">%</span>
                            </div>
                            <div class="metric-chart">
                                <canvas id="spo2Chart"></canvas>
                            </div>
                            <div class="metric-trend">
                                <i class="fas fa-arrow-up trend-up"></i>
                                <span>较上次 +1%</span>
                            </div>
                        </div>
                    </div>

                    <!-- 通讯日志卡片 -->
                    <div class="communication-card">
                        <div class="card-header">
                            <div class="card-title">
                                <i class="fas fa-comments"></i>
                                <span>通讯日志</span>
                            </div>
                            <div class="card-actions">
                                <button class="btn-icon" id="clearLogBtn">
                                    <i class="fas fa-trash"></i>
                                </button>
                                <button class="btn-icon" id="downloadLogBtn">
                                    <i class="fas fa-download"></i>
                                </button>
                            </div>
                        </div>
                        <div class="card-content">
                            <div class="log-container">
                                <textarea id="messageArea" readonly placeholder="等待设备连接..."></textarea>
                            </div>
                            <div class="message-input">
                                <input type="text" id="messageInput" placeholder="发送消息到设备...">
                                <button id="sendBtn" class="btn-primary" disabled>
                                    <i class="fas fa-paper-plane"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- AI助手视图 -->
                <div id="aiView" class="view-section">
                    <div class="ai-container">
                        <div class="ai-header">
                            <div class="ai-avatar">
                                <i class="fas fa-robot"></i>
                            </div>
                            <div class="ai-info">
                                <h2>AI医疗助手</h2>
                                <p>智能分析您的健康数据，提供专业建议</p>
                            </div>
                            <div class="ai-status">
                                <span class="status-badge online">在线</span>
                            </div>
                        </div>

                        <div class="ai-chat-container">
                            <div class="chat-messages" id="aiMessages">
                                <div class="message ai-message">
                                    <div class="message-avatar">
                                        <i class="fas fa-robot"></i>
                                    </div>
                                    <div class="message-content">
                                        <div class="message-text">
                                            您好！我是您的AI医疗助手。我可以帮您分析健康数据、回答医疗问题、提供健康建议。请问有什么可以帮助您的吗？
                                        </div>
                                        <div class="message-time">刚刚</div>
                                    </div>
                                </div>
                            </div>

                            <div class="chat-input-container">
                                <div class="quick-questions">
                                    <button class="quick-btn">分析我的心率数据趋势</button>
                                    <button class="quick-btn">我的体温数据正常吗？</button>
                                    <button class="quick-btn">血氧数据分析和建议</button>
                                    <button class="quick-btn">基于我的数据给出健康建议</button>
                                    <button class="quick-btn">我的数据有什么异常吗？</button>
                                    <button class="quick-btn">滴速数据分析</button>
                                </div>
                                <div class="chat-input">
                                    <input type="text" id="aiMessageInput" placeholder="输入您的问题...">
                                    <button id="aiSendBtn" class="send-btn">
                                        <i class="fas fa-paper-plane"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 数据管理视图 -->
                <div id="dataView" class="view-section">
                    <div class="data-management-container">
                        <!-- 数据查询控制面板 -->
                        <div class="query-panel">
                            <div class="panel-header">
                                <div class="panel-title">
                                    <i class="fas fa-search"></i>
                                    <span>数据查询</span>
                                </div>
                                <button class="collapse-btn" id="collapseQueryBtn">
                                    <i class="fas fa-chevron-up"></i>
                                </button>
                            </div>

                            <div class="panel-content">
                                <!-- 时间范围选择 -->
                                <div class="query-section">
                                    <h4>时间范围</h4>
                                    <div class="time-range-container">
                                        <div class="time-inputs">
                                            <div class="input-field">
                                                <label for="startTime">开始时间</label>
                                                <input type="datetime-local" id="startTime">
                                            </div>
                                            <div class="input-field">
                                                <label for="endTime">结束时间</label>
                                                <input type="datetime-local" id="endTime">
                                            </div>
                                        </div>
                                        <div class="quick-time-buttons">
                                            <button class="quick-time-btn" data-hours="1">1小时</button>
                                            <button class="quick-time-btn" data-hours="24">24小时</button>
                                            <button class="quick-time-btn" data-hours="168">7天</button>
                                            <button class="quick-time-btn" data-hours="720">30天</button>
                                        </div>
                                    </div>
                                </div>

                                <!-- 数据类型选择 -->
                                <div class="query-section">
                                    <h4>数据类型</h4>
                                    <div class="data-type-grid">
                                        <label class="data-type-card">
                                            <input type="checkbox" id="heartCheck" value="Heart" checked>
                                            <div class="card-content">
                                                <i class="fas fa-heartbeat"></i>
                                                <span>心率</span>
                                                <small>BPM</small>
                                            </div>
                                        </label>
                                        <label class="data-type-card">
                                            <input type="checkbox" id="temperatureCheck" value="Temperature" checked>
                                            <div class="card-content">
                                                <i class="fas fa-thermometer-half"></i>
                                                <span>体温</span>
                                                <small>°C</small>
                                            </div>
                                        </label>
                                        <label class="data-type-card">
                                            <input type="checkbox" id="dropRateCheck" value="DropRate" checked>
                                            <div class="card-content">
                                                <i class="fas fa-tint"></i>
                                                <span>滴速</span>
                                                <small>滴/分钟</small>
                                            </div>
                                        </label>
                                        <label class="data-type-card">
                                            <input type="checkbox" id="spo2Check" value="n_spo2" checked>
                                            <div class="card-content">
                                                <i class="fas fa-lungs"></i>
                                                <span>血氧</span>
                                                <small>%</small>
                                            </div>
                                        </label>
                                    </div>
                                </div>

                                <!-- 查询操作 -->
                                <div class="query-actions">
                                    <button id="queryDataBtn" class="btn-primary">
                                        <i class="fas fa-search"></i>
                                        <span>查询数据</span>
                                    </button>
                                    <button id="exportPdfBtn" class="btn-success">
                                        <i class="fas fa-file-pdf"></i>
                                        <span>导出PDF</span>
                                    </button>
                                    <button id="clearDataBtn" class="btn-danger">
                                        <i class="fas fa-trash"></i>
                                        <span>清空数据</span>
                                    </button>
                                    <button id="refreshDataBtn" class="btn-secondary">
                                        <i class="fas fa-sync"></i>
                                        <span>刷新</span>
                                    </button>
                                </div>
                            </div>
                        </div>

                        <!-- 数据统计概览 -->
                        <div class="data-overview">
                            <div class="overview-cards">
                                <div class="overview-card">
                                    <div class="card-icon">
                                        <i class="fas fa-database"></i>
                                    </div>
                                    <div class="card-info">
                                        <span class="card-value" id="totalRecords">0</span>
                                        <span class="card-label">总记录数</span>
                                    </div>
                                </div>
                                <div class="overview-card">
                                    <div class="card-icon">
                                        <i class="fas fa-clock"></i>
                                    </div>
                                    <div class="card-info">
                                        <span class="card-value" id="timeRange">--</span>
                                        <span class="card-label">时间范围</span>
                                    </div>
                                </div>
                                <div class="overview-card">
                                    <div class="card-icon">
                                        <i class="fas fa-chart-bar"></i>
                                    </div>
                                    <div class="card-info">
                                        <span class="card-value" id="dataTypes">--</span>
                                        <span class="card-label">数据类型</span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- 数据表格 -->
                        <div class="data-table-panel">
                            <div class="table-header">
                                <div class="table-title">
                                    <i class="fas fa-table"></i>
                                    <span>数据记录</span>
                                </div>
                                <div class="table-actions">
                                    <button class="btn-icon" id="tableViewBtn" title="表格视图">
                                        <i class="fas fa-table"></i>
                                    </button>
                                    <button class="btn-icon" id="chartViewBtn" title="图表视图">
                                        <i class="fas fa-chart-line"></i>
                                    </button>
                                </div>
                            </div>

                            <div class="table-container">
                                <table id="dataTable" class="modern-table">
                                    <thead>
                                        <tr>
                                            <th>
                                                <i class="fas fa-clock"></i>
                                                时间
                                            </th>
                                            <th>
                                                <i class="fas fa-tag"></i>
                                                类型
                                            </th>
                                            <th>
                                                <i class="fas fa-chart-line"></i>
                                                数值
                                            </th>
                                            <th>
                                                <i class="fas fa-ruler"></i>
                                                单位
                                            </th>
                                            <th>
                                                <i class="fas fa-microchip"></i>
                                                设备
                                            </th>
                                        </tr>
                                    </thead>
                                    <tbody id="dataTableBody">
                                        <tr class="no-data">
                                            <td colspan="5">
                                                <div class="empty-state">
                                                    <i class="fas fa-search"></i>
                                                    <p>暂无数据</p>
                                                    <small>请先执行查询操作</small>
                                                </div>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>

                            <!-- 分页控制 -->
                            <div class="pagination-container">
                                <div class="pagination-info">
                                    <span>第 <strong id="currentPage">1</strong> 页，共 <strong id="totalPages">1</strong> 页</span>
                                </div>
                                <div class="pagination-controls">
                                    <button id="prevPageBtn" class="pagination-btn" disabled>
                                        <i class="fas fa-chevron-left"></i>
                                    </button>
                                    <button id="nextPageBtn" class="pagination-btn" disabled>
                                        <i class="fas fa-chevron-right"></i>
                                    </button>
                                </div>
                                <div class="page-size-selector">
                                    <select id="pageSizeSelect">
                                        <option value="10">10条/页</option>
                                        <option value="20" selected>20条/页</option>
                                        <option value="50">50条/页</option>
                                        <option value="100">100条/页</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 设置视图 -->
                <div id="settingsView" class="view-section">
                    <div class="settings-container">
                        <div class="settings-header">
                            <h2>系统设置</h2>
                            <p>配置系统参数和个性化选项</p>
                        </div>

                        <div class="settings-content">
                            <div class="setting-group">
                                <h3>连接设置</h3>
                                <div class="setting-item">
                                    <label for="serverUrl">服务器地址</label>
                                    <input type="text" id="settingsServerUrl" value="ws://localhost:8080">
                                </div>
                                <div class="setting-item">
                                    <label for="autoConnect">自动连接</label>
                                    <label class="switch">
                                        <input type="checkbox" id="autoConnect">
                                        <span class="slider"></span>
                                    </label>
                                </div>
                            </div>

                            <div class="setting-group">
                                <h3>显示设置</h3>
                                <div class="setting-item">
                                    <label for="darkMode">深色模式</label>
                                    <label class="switch">
                                        <input type="checkbox" id="darkMode">
                                        <span class="slider"></span>
                                    </label>
                                </div>
                                <div class="setting-item">
                                    <label for="animations">动画效果</label>
                                    <label class="switch">
                                        <input type="checkbox" id="animations" checked>
                                        <span class="slider"></span>
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
    </div>

    <!-- 通知弹窗 -->
    <div id="notificationToast" class="notification-toast">
        <div class="toast-content">
            <div class="toast-icon">
                <i class="fas fa-check-circle"></i>
            </div>
            <div class="toast-message">
                <div class="toast-title">操作成功</div>
                <div class="toast-text">您的操作已成功完成</div>
            </div>
            <button class="toast-close">
                <i class="fas fa-times"></i>
            </button>
        </div>
    </div>

    <!-- 确认对话框 -->
    <div id="confirmDialog" class="modal-overlay">
        <div class="modal-content">
            <div class="modal-header">
                <h3>确认操作</h3>
            </div>
            <div class="modal-body">
                <p id="confirmMessage">您确定要执行此操作吗？</p>
            </div>
            <div class="modal-footer">
                <button id="confirmCancel" class="btn-secondary">取消</button>
                <button id="confirmOk" class="btn-primary">确认</button>
            </div>
        </div>
    </div>

    <script src="app.js"></script>
</body>
</html>